
package com.xgry.bpm.api.business.postfiles.controller;

import com.xgry.bpm.common.utils.Result;;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.xgry.bpm.api.business.postfiles.service.PostFilesService;
import com.xgry.bpm.api.business.postfiles.entity. PostFiles;


/**
 * <p>
    *  前端控制器
    * </p>
 *
 * @author adrian
 * @since 2020-07-08
 * @version v1.0
 */
@RestController
@RequestMapping("/post-files")
public class PostFilesController {

    @Autowired
    private PostFilesService ostFilesService;

    /**
     * 查询分页数据
     */
    @ApiOperation(value = "查询分页数据")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "pageIndex", value = "查询第几页", paramType = "query", required = true, dataType = "int"),
        @ApiImplicitParam(name = "pageSize", value = "每页多少条", paramType = "query", required = true, dataType = "int"),
        @ApiImplicitParam(name = "postFiles", value = "客户查询参数", paramType = "query", required = false, dataType = "object")
    })
    @RequestMapping(value = "/getPostFilesListForPage", method= RequestMethod.POST)
    public Result getPostFilesListForPage(@RequestParam(name = "pageIndex", defaultValue = "1") int pageIndex,@RequestParam(name = "pageSize", defaultValue = "5") int pageSize , PostFiles postFiles){
        return Result.convertIpageToSuccess(ostFilesService.page(new Page<>(pageIndex,pageSize),new QueryWrapper<PostFiles>(){{
            this.orderByDesc("pk_id");
            this.setEntity(postFiles);
        }}));
    }


    /**
    * 查询list数据
    */
    @ApiOperation(value = "查询list数据")
    @ApiImplicitParam(name = "查询数据", value = "查询数据", paramType = "query", required = false, dataType = "object")
    @RequestMapping(value = "/getPostFilesList", method= RequestMethod.POST)
    public Result getPostFilesList(PostFiles postFiles){
        return Result.success(HttpStatus.OK.getReasonPhrase(),ostFilesService.list(new QueryWrapper<PostFiles>(){{
            this.orderByAsc("pk_id");
            this.setEntity(postFiles);
        }}));
    }



    /**
     * 新增
     */
    @ApiOperation(value = "新增数据")
    @ApiImplicitParam(name = "postFilesjson", value = "新增数据json", paramType = "query", required = true, dataType = "String")
    @RequestMapping(value = "/addPostFiles", method = RequestMethod.POST)
    public Result addPostFiles(@RequestBody PostFiles postFiles){

        if (null == postFiles) {
            return Result.fail("Obj is null!");
        }

        if (ostFilesService.save(postFiles)) {
            return Result.success();
        }

        return Result.fail();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除数据")
    @ApiImplicitParam(name="用户ids",value = "用户主键id Array",paramType = "delete",required = true,dataType = "int")
    @RequestMapping(value = "/deletePostFilesByIds", method= RequestMethod.POST)
    public Result deletePostFiles(@RequestParam("ids") List<Integer> ids){
        if (CollectionUtils.isEmpty(ids)) {
            return Result.fail("ids is null!");
        }

        if (ostFilesService.removeByIds(ids)) {
            return Result.success();
        }

        return Result.fail();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新数据")
    @ApiImplicitParam(name="用户ids",value = "用户主键id Array",paramType = "update",required = true,dataType = "object")
    @RequestMapping(value = "/updatePostFilesById", method = RequestMethod.POST)
    public Result update(@RequestBody PostFiles postFiles){
        if (null == postFiles ||  0 == postFiles.getPostfilesId().intValue()) {
            return Result.fail("obj is null!");
        }

        if (ostFilesService.updateById(postFiles)) {
            return Result.success();
        }

        return Result.fail();
     }

}
